package com.magic.smartcity.view.more.models

import com.magic.smartcity.beans.ParkBannerBean
import com.magic.smartcity.beans.ParkBean
import com.magic.smartcity.beans.ParkRecordBean
import com.magic.smartcity.utils.HttpClient
import com.magic.smartcity.view.more.models.services.ParkService

/**
 * @description:
 * @create: Create by Magic on 2022/2/23.
 */
class ParkModel {
    val service = HttpClient().retrofit.create(ParkService::class.java)

    /**
     * 获得停车场列表
     */
    fun getParkList(success: (List<ParkBean>) -> Unit, error: (String) -> Unit) {
        service.getParkList().doOnError { it.printStackTrace() }.subscribe {
            if (it.code == 200) {
                success(it.rows)
            } else {
                error(it.msg)
            }
        }
    }

    /**
     * 根据ID获取指定停车场详细信息
     */
    fun getParkById(parkId: Int, success: (ParkBean) -> Unit, error: (String) -> Unit) {
        service.getParkById(parkId).doOnError { it.printStackTrace() }
            .subscribe {
                if (it.code == 200) {
                    success(it.data)
                } else {
                    error(it.msg)
                }
            }
    }

    /**
     * 获得停车历史记录
     */
    fun getParkRecord(success: (List<ParkRecordBean>) -> Unit, error: (String) -> Unit) {
        service.getParkRecord().doOnError { it.printStackTrace() }.subscribe {
            if (it.code==200) {
                success(it.rows)
            }else{
                error(it.msg)
            }
        }
    }

    /**
     * 获得首页轮播图
     */
    fun getBannerList(success: (List<ParkBannerBean>) -> Unit,error: (String) -> Unit){
        service.getBannerList().doOnError{it.printStackTrace()}
            .subscribe{
                if (it.code==200) {
                    success(it.rows)
                }else{
                    error(it.msg)
                }
            }
    }
}